<template>
  <div>
    <el-table style="width: 100%"
              max-height="100%"
              :data="addGroupMsg">
      <el-table-column prop="m_Time"
                       label="日期"
                       sortable
                       width="180">
      </el-table-column>
      <el-table-column prop="m_FromUserID"
                       label="申请人"
                       sortable
                       width="180">
      </el-table-column>
      <el-table-column prop="m_PostMessages.ug_GroupName"
                       label="加入的群">
      </el-table-column>
      <el-table-column label="操作">
        <!-- 插槽操作 -->
        <template slot-scope="scope">
          <el-button type="primary"
                     size="mini"
                     @click="agreeApply(scope.row)">同意</el-button>
          <el-button type="danger"
                     size="mini"
                     @click="delApply(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  name: 'NewGroup',
  props: ['addGroupMsg'],
  created () {
    this.$emit('getAddGroupMsg')
  },
  data () {
    return {
      // 来自发送方的数据
      messageFromSend: {
        M_PostMessages: '', // 发送消息内容
        M_Status: '', // 消息的状态
        M_Time: '', // 发送时间
        M_MessageTypeID: '', // 消息类型
        M_FromUserID: '', // 谁发的
        M_ToUserID: '', // 发给谁
        F_Name: '', // 备注名字
        F_FriendGroup: '', // 分组名字
        M_ID: '' // 消息主键
      }
    }
  },
  methods: {
    // 同意此申请
    agreeApply (data) {
      // this.agreeDialogVisible = true
      this.messageFromSend.M_PostMessages = JSON.stringify(data.m_PostMessages)
      this.messageFromSend.M_Status = data.m_Status
      this.messageFromSend.M_Time = data.m_Time
      this.messageFromSend.M_MessageTypeID = data.m_MessageTypeID
      this.messageFromSend.M_FromUserID = data.m_FromUserID
      this.messageFromSend.M_ToUserID = data.m_ToUserID
      this.messageFromSend.M_ID = data.m_ID
      var qs = require('qs')
      this.$http.post('agreeApplyGroup', qs.stringify(this.messageFromSend))
        .then((response) => {
          const res = response.data
          if (res.code !== 200) return this.$message.error(res.msg)
          else {
            return this.$message.success(res.msg)
          }
        })
    },
    // 拒绝此申请
    delApply (data) {
      this.$http.get('delApplyGroup', { params: { UG_ID: data.m_ID } }).then((response) => {
        const res = response.data
        if (res.code !== 200) return this.$message.error(res.msg)
        // 刷新
        this.$emit('refresh')
        this.$message.success(res.msg)
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>
